/**
 * Copyright (C) 2008-2025 isoft Infrastructure Software Co., Ltd.
 * SPDX-License-Identifier: LGPL-2.1-only-with-exception
 *
 * This library is free software; you can redistribute it and/or modify it under the terms of the
 * GNU Lesser General Public License as published by the Free Software Foundation; version 2.1.
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License along with this library;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 * or see <https://www.gnu.org/licenses/>.
 */
/*
 ************************************************************************************************************************
 **
 **  @file               : TcpIp.h
 **  @author             : darren.zhang
 **  @date               : 2018/12/03
 **  @vendor             : isoft
 **  @description        : TcpIp header file for extern API declarations
 **
 ***********************************************************************************************************************/
/** ====================================================================================================================
 *  REVISION HISTORY
 *  -------------------------------------------------------------------------------------------------------------------
 *  Version   Date        Author          Description
 *  -------------------------------------------------------------------------------------------------------------------
 *  V1.0.0    20190813    zhengfei.li     Initial version
 *  V2.0.0    20200828    pengfei.zhu     Update to R19-11. Tcp/Udp_CopyTxData now have synchronous process.
 *                                        Add Tcp_Tls function. Add Enable/Disable Nagle algorithm of newPcb
 *                                        generated by listenPcb in TcpIp_TcpAcceptCallcback.
 *  V2.0.1    20200928    pengfei.zhu     QAC test.
 *  V2.0.2    20210817    darren.zhang    Code refactoring ,include code style and tls handle
 *  V2.0.3    20220802    darren.zhang    1. create tcp or udp socket add schm protect.
 *                                        2. default open ETHERNET_CHECK,avoid exceptions caused by
 *                                           ethIF return failure.
 *  V2.0.4    20221020    darren.zhang    add tc8 test api
 *  V2.0.5    20221118    darren.zhang    pbuf is abnormal because arp sending is interrupted by receiving interruption
 *  V2.0.6    20221121    fupeng.yu       merge BsdTcpIp
 *  V2.0.7    20221121    darren.zhang    Features:support socket vlan
 *  V2.0.8    20230206    darren.zhang    tcp socket option SocketTcpKeepAliveProbesMax data type conversion modify
 *  V2.0.9    20230527    darren.zhang    1. ethernet.c call EthIf_Transmit input parameter modify (CPT-439)
 *                                        2. tcp tp transmit handle logical adjustments when the buffer runs out
 *  V2.0.10   20230725    darren.zhang    1. lwip:reslove the response mismatch on the multi-network port tcp server
 *                                        2. lwip:etharp.c support only static arp
 *  V2.0.11   20230801    fupeng.yu       add TcpIp_TcpShutdown for tc8 test
 *  V2.0.12   20230802    fupeng.yu       TcpIp_Internal.c In TcpIp_PeriodTimerMainHandle,Modify the logic of period
 *                                        processing,resolve the period is inaccurate
 *  V2.0.13   20230804    fupeng.yu       TcpIp_Internal.c add TcpIp_GetControlIpFramePriority for the priority for all
 *                                        outgoing frames
 *  V2.0.14   20230814    fupeng.yu       1. TcpIp_Internal.c In TcpIp_UdpTransmitLocalIpCompare, Modify conditional
 *                                           compilation
 *                                        2. Resolve QAC
 *  V2.0.15   20230816    fupeng.yu       TcpIp_Internal.c In TcpIp_MallocTcpSocketIdByPcb,Resolve the socketflag of tcp
 *                                        server is modified by new created socket
 *  V2.0.16   20230828    fupeng.yu       1. TcpIp_Internal.c Modify the judgment conditions of netif->name[1] in
 *                                           TCPIP_CHECK_NETIF_ETHIF_CTRLINDEX
 *                                        2. TcpIp.c Add mapping EthIf CtrlIdx to TcpIp CtrlIdx
 *  V2.0.17   20230925    darren.zhang    1. support ipref2
 *                                        2. tcp tc8 empty ack modify
 *                                        3. delete half close tcp macro define
 *                                        4. support ip header set df bit
 *  V2.0.18   20231207    fupeng.yu       1. TcpIp_Internal.c Check the validity of the IP address when clearing
 *                                           the local IP address in TcpIp_ClearLocalAdrIpVar
 *                                        2. TcpIp_Internal.c Check the validity of IP address when forcibly
 *                                           notifying upper layers and the ipAdrState is ASSIGNED
 *                                           in TcpIp_CtrlLinkLocalAddrChagneHandle
 *  V2.0.19   20231207    fupeng.yu       TcpIp_Internal.c report runtime error when the return value of
 *                                        bind() is ERR_USE in TcpIp_InnerBind
 *  V2.0.20   20240129    fupeng.yu       supported localAddrId is TCPIP_LOCALADDRID_ANY for tcpip_bind()
 *  V2.0.21   20240502    fupeng.yu       support configuration of static arp table
 *  V2.0.22   20240509    fupeng.yu       Remove nesting of the same exclusive area
 *  V2.0.23   20240618    darren.zhang    modify bsd tcpip used schm
 *  V2.0.24   20240624    fupeng.yu       TcpIp_Internal.c resolve incorrect calculation of netmask in
 *                                        TcpIp_NetMaskInnerToExt
 *  V2.0.25   20240712    fupeng.yu       Modify obtaining TCP closed status for TC8 test
 *  V2.0.26   20240725    fupeng.yu       check the configuration of static ARP during initialization
 *  V2.0.27   20240729    fupeng.yu       move the posiition of the TCPIP_LOCALADR_CLR_IPVALID in
 *                                        TcpIp_ClearLocalAdrIpVar
 *  V2.0.28   20240814    fupeng.yu       modify transmission of TP for the TcpTransmit
 *  V2.1.0    20241205    miao.wang       R23-11 development first release.
 ==================================================================================================================== */

/* ================================================ misar justifications ============================================ */
/**
  \page ISOFT_MISRA_Exceptions  MISRA-C:2023 Compliance Exceptions
    ModeName:TcpIp<br>
  RuleSource:puhua-rule.rcf 3.0.0

    \li VL_TcpIp_2991
      Reason: The control statement has no effect, but is reserved for better readability.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_2992
      Reason: The control statement has no effect, but is reserved for better readability.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_2995
      Reason: The control statement has no effect, but is reserved for better readability.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_2996
      Reason: The control statement has no effect, but is reserved for better readability.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_2916
      Reason: The assignment is reserved for better readibility.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_2982
      Reason: The assignment is reserved for better readibility.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_2983
      Reason: The assignment is reserved for better readibility.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_0488
      Reason: The arithmetic is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_0499
      Reason: The arithmetic is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_1258
      Reason: The cast conversion is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_1259
      Reason: The cast conversion is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_1290
      Reason: The cast conversion is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_2144
      Reason: The cast conversion is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_4391
      Reason: The cast conversion is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_4393
      Reason: The cast conversion is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_4397
      Reason: The cast conversion is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_1338
      Reason: The parameter is an in/out parameter, and is intended to be modified.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_1277
      Reason: The macro value is defined in lwIp.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_3631
      Reason: The data type is defined in lwIp.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_1334
      Reason: Only parameter name is different.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_1339
      Reason: The evaluation of parameter address is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_1860
      Reason: The arithmetic is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_0311
      Reason: The cast conversion is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_0314
      Reason: The cast conversion is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_2743
      Reason: The do-while structure is reserved for better readability.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_5016
      Reason: The data type is defined in lwIp.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_2106
      Reason: The conversion is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_2140
      Reason: The conversion is safe.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_3472
      Reason: The macro is reserved.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_3473
      Reason: The macro is reserved.
      Risk: No risk.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_FlexibleArray
      Reason: Misidentify flexible array.
      Risk: None.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_3218
      Reason: Defined at file scope deliberately in order to assist in debugging.
      Risk: None.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_1253
      Reason: The macro is defined in lwIp.
      Risk: None.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_1840
      Reason: The macro is defined in lwIp.
      Risk: None.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_1505
      Reason: The internal functions are all defined in the TcpIp_Internal.c file.
      Risk: None.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_TcpIp_3123
      Reason: The magic number can be easily understood according to the context.
      Risk: None.
      Prevention: Ensure that the project is working properly through unit testing.

    \li VL_MTR_TcpIp_STVAR
      Reason: The function prototype is defined in AUTOSAR standard.
      Risk: The code is difficult to maintain.
      Prevention: Design and code review, and have a clear structure and annotated code.

    \li VL_MTR_TcpIp_CONF
      Reason: The implementation is completely in accordance with the specification.
      Risk: None.
      Prevention: None.

    \li VL_MTR_TcpIp_STCAL
      Reason: The software structure is defined according to the AUTOSAR standard.
      Risk: Understandability and testability become overly complex
      Prevention: Design and code review, and have a clear structure and annotated code.

    \li VL_MTR_TcpIp_STMIF
      Reason: Functions have different scenarios that need to be covered, which depends on the configuration of
              different channels, sdu and other configuration conditions, as well as some precompiled macros.
      Risk: The code is difficult to maintain.
      Prevention: Design and code review, and have a clear structure and annotated code.

    \li VL_MTR_TcpIp_STPAR
      Reason: The external API of DcmClient is based on the design requirements for sending as an external
              interface service, resulting in its metric being higher than the threshold
      Risk: For the target uC, the stack usage and runtime are too high.
      Prevention: When testing the result code on the target uC, the user must check the stack usage in the
                  project context.
 */

#ifndef TCPIP_H_
#define TCPIP_H_

/* =================================================== inclusions =================================================== */
#include "TcpIp_Cfg.h"
#if (STD_ON == TCPIP_PARTITION_USED)
#include "Os_Types.h"
#endif
#include "ComStack_Types.h"
#include "TcpIp_PBcfg.h"
#include "TcpIp_Types.h"
#include "TcpIp_CfgTypes.h"

#include "TcpIp_SocketOwner.h"
#include "Eth_GeneralTypes.h"
#include "SchM_TcpIp.h"

#ifdef __cplusplus
extern "C" {
#endif

/* =============================================== version information ============================================== */
/**
 * @name TcpIpPublishedInfoMcros
 * @{
 * @brief Published information
 */
#define TCPIP_VENDOR_ID                   62u  /**< Vendor Id */
#define TCPIP_MODULE_ID                   170u /**< Module Id */
#define TCPIP_AR_RELEASE_MAJOR_VERSION    4u   /**< AR release major version */
#define TCPIP_AR_RELEASE_MINOR_VERSION    9u   /**< AR release minor version */
#define TCPIP_AR_RELEASE_REVISION_VERSION 0u   /**< AR release patch version */
/**
 * @}
 */

/**
 * @name TcpIpComponentVersionMacros
 * @{
 * @brief Component version information
 */
#define TCPIP_SW_MAJOR_VERSION 2u /**< Software major version */
#define TCPIP_SW_MINOR_VERSION 1u /**< Software minor version */
#define TCPIP_SW_PATCH_VERSION 0u /**< Software patch version */
/**
 * @}
 */

/* ===================================================== macros ===================================================== */
/**
 * @brief Instance Id
 */
#define TCPIP_INSTANCE 0u

/* ================================================ type definitions ================================================ */

/* ========================================== internal function definitions ========================================= */

/* =========================================== external data declarations =========================================== */

/* ========================================= external function declarations ========================================= */
/**
 * @brief           This service initializes the TCP/IP Stack. TcpIp_Init may not block the start-up
                    process for an indefinite amount of time.
 * @param[in]       ConfigPtr: Pointer to the configuration data of the TcpIp module
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69648
 */
extern void TcpIp_Init(const TcpIp_ConfigType* ConfigPtr);

#if (STD_ON == TCPIP_VERSION_INFO_API)
/**
 * @brief           Returns the version information.
 * @param[out]      versioninfo: Pointer to where to store the version information of this module.
 * @synchronous     TRUE
 * @reentrant       Reentrant
 * @trace           CPD-69649
 */
extern void TcpIp_GetVersionInfo(Std_VersionInfoType* versioninfo);
#endif

/**
 * @brief           By this API service the TCP/IP stack is requested to close the socket and release
                    all related resources.
 * @param[in]       SocketId: Socket handle identifying the local socket resource.
 * @param[in]       Abort:
                    TRUE: connection will immediately be terminated by sending a RST-Segment and
                    releasing all related resources.
                    FALSE: connection will be terminated after performing a regular connection termination
                    handshake and releasing all related resources.
 * @return          Std_ReturnType
 * @retval          E_OK: The request has been accepted.
 * @retval          E_NOT_OK: The request has not been accepted.
 * @synchronous     FALSE
 * @reentrant       Reentrant for different SocketIds. Non reentrant for the same SocketId.
 * @trace           CPD-69650
 */
extern Std_ReturnType TcpIp_Close(TcpIp_SocketIdType SocketId, boolean Abort);

/**
 * @brief           By this API service the TCP/IP stack is requested to bind a UDP or TCP socket to
                    a local resource.
 * @param[in]       SocketId: Socket identifier of the related local socket resource.
 * @param[in]       LocalAddrId: IP address identifier representing the local IP address and EthIf
                    controller to bind the socket to.
 * @param[inout]    PortPtr: Pointer to memory where the local port to which the socket shall be bound
                    is specified. In case the parameter is specified as TCPIP_PORT_ANY, the TCP/IP stack
                    shall choose the local port automatically from the range 49152 to 65535 and shall
                    update the parameter to the chosen value.
 * @return          Std_ReturnType
 * @retval          E_OK: The request has been accepted.
 * @retval          E_NOT_OK: The request has not been accepted (e.g. address in use).
 * @synchronous     TRUE
 * @reentrant       Reentrant for different SocketIds. Non reentrant for the same SocketId.
 * @trace           CPD-69651
 */
extern Std_ReturnType TcpIp_Bind(TcpIp_SocketIdType SocketId, TcpIp_LocalAddrIdType LocalAddrId, uint16* PortPtr);

#if (STD_ON == TCPIP_TCP_ENABLED)
/**
 * @brief           By this API service the TCP/IP stack is requested to establish a TCP connection to
                    the configured peer.
 * @param[in]       SocketId: Socket identifier of the related local socket resource.
 * @param[in]       RemoteAddrPtr: IP address and port of the remote host to connect to.
 * @return          Std_ReturnType
 * @retval          E_OK: The request has been accepted.
 * @retval          E_NOT_OK: The request has not been accepted, e.g. connection is already established
                    or no route to destination specified by remoteAddrPtr found.
 * @synchronous     FALSE
 * @reentrant       Reentrant for different SocketIds. Non reentrant for the same SocketId.
 * @trace           CPD-69652
 */
extern Std_ReturnType TcpIp_TcpConnect(TcpIp_SocketIdType SocketId, const TcpIp_SockAddrType* RemoteAddrPtr);

/**
 * @brief           By this API service the TCP/IP stack is requested to listen on the TCP socket
                    specified by the socket identifier.
 * @param[in]       SocketId: Socket identifier of the related local socket resource.
 * @param[in]       MaxChannels: Maximum number of new parallel connections established on this
                    listen connection.
 * @return          Std_ReturnType
 * @retval          E_OK: The request has been accepted.
 * @retval          E_NOT_OK: The request has not been accepted, the socket is not configured to be
                    a server socket.
 * @synchronous     FALSE
 * @reentrant       Reentrant for different SocketIds. Non reentrant for the same SocketId.
 * @trace           CPD-69653
 */
extern Std_ReturnType TcpIp_TcpListen(TcpIp_SocketIdType SocketId, uint16 MaxChannels);

/**
 * @brief           By this API service the reception of socket data is confirmed to the TCP/IP stack.
 * @param[in]       SocketId: Socket identifier of the related local socket resource.
 * @param[in]       Length: Number of bytes finally consumed by the upper layer.
 * @return          Std_ReturnType
 * @retval          E_OK: The request has been accepted.
 * @retval          E_NOT_OK: The request has not been accepted.
 * @synchronous     FALSE
 * @reentrant       Reentrant for different SocketIds. Non reentrant for the same SocketId.
 * @trace           CPD-69654
 */
extern Std_ReturnType TcpIp_TcpReceived(TcpIp_SocketIdType SocketId, uint32 Length);
#endif

/**
 * @brief           By this API service the TCP/IP stack is requested to change the TcpIp state of the
                    communication network identified by EthIf controller index.
 * @param[in]       CtrlIdx: EthIf controller index to identify the communication network where the
                    TcpIp state is requested.
 * @param[in]       State: Requested TcpIp state.
 * @return          Std_ReturnType
 * @retval          E_OK: Service accepted.
 * @retval          E_NOT_OK: Service denied.
 * @synchronous     FALSE
 * @reentrant       Non reentrant
 * @trace           CPD-69655
 */
extern Std_ReturnType TcpIp_RequestComMode(uint8 CtrlIdx, TcpIp_StateType State);

/**
 * @brief           By this API service the local IP address assignment for the IP address
                    specified by LocalAddrId shall be initiated.
 * @param[in]       LocalAddrId: IP address index specifying the IP address for which an
                    assignment shall be initiated.
 * @param[in]       Type: Type of IP address assignment which shall be initiated.
 * @param[in]       LocalIpAddrPtr: Pointer to structure containing the IP address which shall
                    be assigned to the EthIf controller indirectly specified via LocalAddr Id.
 * @param[in]       Netmask: Network mask of IPv4 address or address prefix of IPv6 address
                    in CIDR Notation.
 * @param[in]       DefaultRouterPtr: Pointer to structure containing the IP address of the
                    default router (gateway) which shall be assigned.
 * @return          Std_ReturnType
 * @retval          E_OK: The request has been accepted.
 * @retval          E_NOT_OK: The request has not been accepted.
 * @synchronous     FALSE
 * @reentrant       Non reentrant
 * @trace           CPD-69656
 */
extern Std_ReturnType TcpIp_RequestIpAddrAssignment(
    TcpIp_LocalAddrIdType      LocalAddrId,
    TcpIp_IpAddrAssignmentType Type,
    const TcpIp_SockAddrType*  LocalIpAddrPtr,
    uint8                      Netmask,
    const TcpIp_SockAddrType*  DefaultRouterPtr);

/**
 * @brief           By this API service the local IP address assignment for the IP address specified
                    by LocalAddrId shall be released.
 * @param[in]       LocalAddrId: IP address index specifying the IP address for which an assignment
                    shall be released.
 * @return          Std_ReturnType
 * @retval          E_OK: The request has been accepted.
 * @retval          E_NOT_OK: The request has not been accepted.
 * @synchronous     FALSE
 * @reentrant       Non reentrant
 * @trace           CPD-69657
 */
extern Std_ReturnType TcpIp_ReleaseIpAddrAssignment(TcpIp_LocalAddrIdType LocalAddrId);

#if ((STD_ON == TCPIP_DHCP_CLIENT_ENABLED) && (STD_ON == TCPIP_RESET_IP_ASSIGNMENT_API))
/**
 * @brief           Resets all learned IP-addresses to invalid values.
 * @return          Std_ReturnType
 * @retval          E_OK: success.
 * @retval          E_NOT_OK: switch port could not be initialized.
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69658
 */
extern Std_ReturnType TcpIp_ResetIpAssignment(void);
#endif

#if (STD_ON == TCPIP_ICMP_ENABLED)
#if ((TCPIP_SC1 == TCPIP_SCALABILITY_CLASS) || (TCPIP_SC3 == TCPIP_SCALABILITY_CLASS))
/**
 * @brief           By this API service the TCP/IP stack sends an ICMP message according to the
                    specified parameters.
 * @param[in]       LocalIpAddrId: IP address identifier representing the local IP address and EthIf
                    controller which shall be used for transmission of the ICMP message.
 * @param[in]       RemoteAddrPtr: pointer to struct representing the remote address.
 * @param[in]       Ttl: Time to live value to be used for the ICMP message. If 0 is specified the
                    default value shall be used.
 * @param[in]       Type: type field value to be used in the ICMP message.
 * @param[in]       Code: code field value to be used in the ICMP message.
 * @param[in]       DataLength: length of ICMP message.
 * @param[in]       DataPtr: Pointer to data which shall be sent as ICMP message data
 * @return          Std_ReturnType
 * @retval          E_OK: The ICMP message has been sent successfully.
 * @retval          E_NOT_OK: The ICMP message was not sent.
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69659
 */
extern Std_ReturnType TcpIp_IcmpTransmit(
    TcpIp_LocalAddrIdType     LocalIpAddrId,
    const TcpIp_SockAddrType* RemoteAddrPtr,
    uint8                     Ttl,
    uint8                     Type,
    uint8                     Code,
    uint16                    DataLength,
    const uint8*              DataPtr);
#endif

#if ((TCPIP_SC2 == TCPIP_SCALABILITY_CLASS) || (TCPIP_SC3 == TCPIP_SCALABILITY_CLASS))
/**
 * @brief           By this API service the TCP/IP stack sends an ICMPv6 message according to
                    the specified parameters.
 * @param[in]       LocalIpAddrId: IP address identifier representing the local IP address and
                    EthIf controller which shall be used for transmission of the ICMPv6 message.
 * @param[in]       RemoteAddrPtr: pointer to struct representing the remote address.
 * @param[in]       HopLimit: Hop Limit value to be used for the ICMPv6 message.
                    If 0 is specified the default value shall be used.
 * @param[in]       Type: type field value to be used in the ICMPv6 message.
 * @param[in]       Code: code field value to be used in the ICMPv6 message.
 * @param[in]       DataLength: length of ICMPv6 message.
 * @param[in]       DataPtr: Pointer to data which shall be sent as ICMPv6 message data.
 * @return          Std_ReturnType
 * @retval          E_OK: The ICMPv6 message has been sent successfully.
 * @retval          E_NOT_OK: The ICMPv6 message was not sent.
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69660
 */
extern Std_ReturnType TcpIp_IcmpV6Transmit(
    TcpIp_LocalAddrIdType     LocalIpAddrId,
    const TcpIp_SockAddrType* RemoteAddrPtr,
    uint8                     HopLimit,
    uint8                     Type,
    uint8                     Code,
    uint16                    DataLength,
    const uint8*              DataPtr);
#endif
#endif

#if ((TCPIP_SC1 == TCPIP_SCALABILITY_CLASS) || (TCPIP_SC3 == TCPIP_SCALABILITY_CLASS))
/**
 * @brief           By this API service the TCP/IP stack retrieves DHCP option data identified by
                    parameter option for already received DHCP options.
 * @param[in]       LocalIpAddrId: IP address identifier representing the local IP address and EthIf
                    controller for which the DHCP option shall be read.
 * @param[in]       Option: DHCP option (note: according to IANA DHCP Options).
 * @param[inout]    DataLength: As input parameter, contains the length of the provided data buffer.
                    Will be overwritten with the length of the actual data.
 * @param[out]      DataPtr: Pointer to memory containing DHCP option data.
 * @return          Std_ReturnType
 * @retval          E_OK: requested data retrieved successfully.
 * @retval          E_NOT_OK: requested data could not be retrieved.
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69661
 */
extern Std_ReturnType
    TcpIp_DhcpReadOption(TcpIp_LocalAddrIdType LocalIpAddrId, uint8 Option, uint8* DataLength, uint8* DataPtr);
#endif

#if ((TCPIP_SC2 == TCPIP_SCALABILITY_CLASS) || (TCPIP_SC3 == TCPIP_SCALABILITY_CLASS))
/**
 * @brief           By this API service the TCP/IP stack retrieves DHCPv6 option data identified by
                    parameter option for already received DHCPv6 options.
 * @param[in]       LocalIpAddrId: IP address identifier representing the local IP address and EthIf
                    controller for which the DHCPv6 option shall be read.
 * @param[in]       Option: DHCP option (note: according to IANA DHCP[v6] Options).
 * @param[inout]    DataLength: As input parameter, contains the length of the provided data buffer.
                    Will be overwritten with the length of the actual data.
 * @param[out]      DataPtr: Pointer to memory containing DHCPv6 option data.
 * @return          Std_ReturnType
 * @retval          E_OK: requested data retrieved successfully.
 * @retval          E_NOT_OK: requested data could not be retrieved.
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69662
 */
extern Std_ReturnType
    TcpIp_DhcpV6ReadOption(TcpIp_LocalAddrIdType LocalIpAddrId, uint16 Option, uint16* DataLength, uint8* DataPtr);
#endif

#if ((TCPIP_SC1 == TCPIP_SCALABILITY_CLASS) || (TCPIP_SC3 == TCPIP_SCALABILITY_CLASS))
/**
 * @brief           By this API service the TCP/IP stack writes the DHCP option data identified
                    by parameter option.
 * @param[in]       LocalIpAddrId: IP address identifier representing the local IP address and
                    EthIf controller for which the DHCP option shall be written.
 * @param[in]       Option: DHCP option (note: according to IANA DHCP Options).
 * @param[in]       DataLength: length of DHCP option data.
 * @param[in]       DataPtr: Pointer to memory containing DHCP option data
 * @return          Std_ReturnType
 * @retval          E_OK: no error occured.
 * @retval          E_NOT_OK: DHCP option data could not be written.
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69663
 */
extern Std_ReturnType
    TcpIp_DhcpWriteOption(TcpIp_LocalAddrIdType LocalIpAddrId, uint8 Option, uint8 DataLength, const uint8* DataPtr);
#endif

#if ((TCPIP_SC2 == TCPIP_SCALABILITY_CLASS) || (TCPIP_SC3 == TCPIP_SCALABILITY_CLASS))
/**
 * @brief           By this API service the TCP/IP stack writes the DHCPv6 option data identified
                    by parameter option.
 * @param[in]       LocalIpAddrId: IP address identifier representing the local IP address and
                    EthIf controller for which the DHCPv6 option shall be written.
 * @param[in]       Option: DHCP option (note: according to IANA DHCP[v6] Options).
 * @param[in]       DataLength: length of DHCPv6 option data.
 * @param[in]       DataPtr: Pointer to memory containing DHCPv6 option data.
 * @return          Std_ReturnType
 * @retval          E_OK: no error occured.
 * @retval          E_NOT_OK: DHCPv6 option data could not be written.
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69664
 */
extern Std_ReturnType TcpIp_DhcpV6WriteOption(
    TcpIp_LocalAddrIdType LocalIpAddrId,
    uint16                Option,
    uint16                DataLength,
    const uint8*          DataPtr);
#endif

/**
 * @brief           By this API service the TCP/IP stack is requested to change a parameter of a socket.
                    E.g. the Nagle algorithm may be controlled by this API.
 * @param[in]       SocketId: Socket identifier of the related local socket resource.
 * @param[in]       ParameterId: Identifier of the parameter to be changed.
 * @param[in]       ParameterValue: Pointer to memory containing the new parameter value.
 * @return          Std_ReturnType
 * @retval          E_OK: The parameter has been changed successfully.
 * @retval          E_NOT_OK: The parameter could not be changed.
 * @synchronous     TRUE
 * @reentrant       Reentrant for different SocketIds. Non reentrant for the same SocketId.
 * @trace           CPD-69665
 */
extern Std_ReturnType
    TcpIp_ChangeParameter(TcpIp_SocketIdType SocketId, TcpIp_ParamIdType ParameterId, const uint8* ParameterValue);

/**
 * @brief           Obtains the local IP address actually used by LocalAddrId, the netmask and
                    default router.
 * @param[in]       LocalAddrId: Local address identifier referring to the local IP address which
                    shall be obtained.
 * @param[inout]    IpAddrPtr: Pointer to a struct where the IP address shall be stored. The struct
                    member domain shall be set to the desired TcpIp_Domain Type and it shall be
                    ensured that the struct is large enough to store an address of the selected type
                    (INET or INET6). Struct members not related to the IP address are of arbitrary
                    value and shall not be used.
 * @param[inout]    DefaultRouterPtr: Pointer to struct where the IP address of the default router
                    (gateway) is stored (struct member "port" is not used and of arbitrary value).
                    The struct must be of the same type and size as IpAddrPtr.
 * @param[out]      NetmaskPtr: Pointer to memory where Network mask of IPv4 address or address prefix
                    of IPv6 address in CIDR Notation is stored.
 * @return          Std_ReturnType
 * @retval          E_OK: The request was successful.
 * @retval          E_NOT_OK: The request was not successful, e.g. domain in Ip AddrPtr and the local
                    domain type do not match.
 * @synchronous     TRUE
 * @reentrant       Reentrant
 * @trace           CPD-69666
 */
extern Std_ReturnType TcpIp_GetIpAddr(
    TcpIp_LocalAddrIdType LocalAddrId,
    TcpIp_SockAddrType*   IpAddrPtr,
    uint8*                NetmaskPtr,
    TcpIp_SockAddrType*   DefaultRouterPtr);

/**
 * @brief           Obtains the physical source address used by the EthIf controller implicitly
                    specified via Local AddrId.
 * @param[in]       LocalAddrId: Local address identifier implicitely specifing the EthIf controller
                    for which the physical address shall be obtained.
 * @param[out]      PhysAddrPtr: Pointer to the memory where the physical source address (MAC address)
                    in network byte order is stored.
 * @return          Std_ReturnType
 * @retval          E_OK: The request was successful.
 * @retval          E_NOT_OK: The request was not successful, e.g. no unique Ctrl specified via IpAddrId.
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69667
 */
extern Std_ReturnType TcpIp_GetPhysAddr(TcpIp_LocalAddrIdType LocalAddrId, uint8* PhysAddrPtr);

/**
 * @brief           TcpIp_GetRemotePhysAddr queries the IP/physical address translation table specified
                    by Ctrl Idx and returns the physical address related to the IP address specified by
                    IpAddrPtr. In case no physical address can be retrieved and parameter initRes is TRUE,
                    address resolution for the specified IP address is initiated on the local network.
 * @param[in]       CtrlIdx: EthIf controller index to identify the related ARP/NDP table.
 * @param[in]       IpAddrPtr: specifies the IP address for which the physical address shall be retrieved.
 * @param[in]       initRes: specifies if the address resolution shall be initiated (TRUE) or not (FALSE)
                    in case the physical address related to the specified IP address is currently unknown.
 * @param[out]      PhysAddrPtr: Pointer to the memory where the physical address (MAC address) related
                    to the specified IP address is stored in network byte order.
 * @return          TcpIp_ReturnType
 * @retval          TCPIP_E_OK: specified IP address resolved, physical address provided via PhysAddrPtr.
 * @retval          TCPIP_E_PHYS_ADDR_MISS: physical address currently unknown (address resolution
                    initiated if initRes set to TRUE).
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69668
 */
extern TcpIp_ReturnType
    TcpIp_GetRemotePhysAddr(uint8 CtrlIdx, const TcpIp_SockAddrType* IpAddrPtr, uint8* PhysAddrPtr, boolean initRes);

/**
 * @brief           TcpIp_GetCtrlIdx returns the index of the controller related to LocalAddrId.
 * @param[in]       LocalAddrId: Local address identifier implicitely specifing the EthIf controller
                    that shall be returned.
 * @param[out]      CtrlIdxPtr: Pointer to the memory where the index of the controller related to
                    LocalAddrId is stored.
 * @return          Std_ReturnType
 * @retval          E_OK: the request was successful.
 * @retval          E_NOT_OK: the request was not successful.
 * @synchronous     TRUE
 * @reentrant       Reentrant
 * @trace           CPD-69669
 */
extern Std_ReturnType TcpIp_GetCtrlIdx(TcpIp_LocalAddrIdType LocalAddrId, uint8* CtrlIdxPtr);

/**
 * @brief           Copies entries from the physical address cache of the IPv4 instance that is active
                    on the EthIf controller specified by ctrlIdx into a user provided buffer. The function
                    will copy all or numberOf Elements into the output list. If input value of
                    numberOfElements is 0 the function will not copy any data but only return the number
                    of valid entries in the cache. EntryListPtr may be NULL_ PTR in this case.
 * @param[in]       ctrlIdx: EthIf controller index to identify the related ARP table.
 * @param[inout]    numberOfElements:
                    In: Maximum number of entries that can be stored in output entry ListPtr.
                    Out: Number of entries written to output entryListPtr (Number of all entries in the
                    cache if input value is 0).
 * @param[out]      entryListPtr: Pointer to memory where the list of cache entries shall be stored.
 * @return          Std_ReturnType
 * @retval          E_OK: physical address cache could be read.
 * @retval          E_NOT_OK: physical address cache could not be read (i.e. no IPv4 instance active
                    on this controller).
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69670
 */
extern Std_ReturnType
    TcpIp_GetArpCacheEntries(uint8 ctrlIdx, uint32* numberOfElements, TcpIp_ArpCacheEntryType* entryListPtr);

/**
 * @brief           Copies entries from the physical address cache of the IPv6 instance that is active
                    on the EthIf controller specified by ctrlIdx into a user provided buffer. The
                    function will copy all or numberOf Elements into the output list. If input value of
                    numberOfElements is 0 the function will not copy any data but only return the number
                    of valid entries in the cache. EntryListPtr may be NULL_ PTR in this case.
 * @param[in]       ctrlIdx: EthIf controller index to identify the related NDP table.
 * @param[inout]    numberOfElements:
                    In: Maximum number of entries that can be stored in output entry ListPtr.
                    Out: Number of entries written to output entryListPtr (Number of all entries in the
                    cache if input value is 0).
 * @param[out]      entryListPtr: Pointer to memory where the list of cache entries shall be stored.
 * @return          Std_ReturnType
 * @retval          E_OK: physical address cache could be read.
 * @retval          E_NOT_OK: physical address cache could not be read (i.e. no IPv6 instance active on
                    this controller).
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69671
 */
extern Std_ReturnType
    TcpIp_GetNdpCacheEntries(uint8 ctrlIdx, uint32* numberOfElements, TcpIp_NdpCacheEntryType* entryListPtr);

/**
 * @brief           Allows to read and reset detailed measurement data for diagnostic purposes.
                    Get all MeasurementIdx's at once is not supported. TCPIP_MEAS_ALL shall only
                    be used to reset all MeasurementIdx's at once. A NULL_PTR shall be provided
                    for MeasurementDataPtr in this case.
 * @param[in]       MeasurementIdx: Data index of measurement data
 * @param[in]       MeasurementResetNeeded: Flag to trigger a reset of the measurement data
 * @param[out]      MeasurementDataPtr: Reference to data buffer, where to copy measurement data
 * @return          Std_ReturnType
 * @retval          E_OK: successful.
 * @retval          E_NOT_OK: failed.
 * @synchronous     TRUE
 * @reentrant       Reentrant
 * @trace           CPD-69672
 */
extern Std_ReturnType TcpIp_GetAndResetMeasurementData(
    TcpIp_MeasurementIdxType MeasurementIdx,
    boolean                  MeasurementResetNeeded,
    uint32*                  MeasurementDataPtr);

/**
 * @brief           API allows to check if a communication over this socket is possible for
                    a dedicated remote address. It includes that the socket is bound, a physical
                    address is available for the requested remote address and if a security
                    association is configured that a secured connection is already established.
 * @param[in]       SocketId: Socket handle identifying the local socket resource.
 * @param[in]       RemoteAddrPtr: Pointer to the structure containing the requested remote IP
                    address and port.
 * @return          TcpIp_ReturnType
 * @retval          TCPIP_E_OK: SocketId is ready for communication.
 * @retval          TCPIP_E_NOT_OK: Request was rejected.
 * @retval          TCPIP_E_PENDING: Connection establishment in progress.
 * @synchronous     TRUE
 * @reentrant       Reentrant for different SocketIds. Non reentrant for the same SocketId.
 * @trace           CPD-69673
 */
extern TcpIp_ReturnType TcpIp_IsConnectionReady(TcpIp_SocketIdType SocketId, const TcpIp_SockAddrType* RemoteAddrPtr);

#if (STD_ON == TCPIP_UDP_ENABLED)
/**
 * @brief           This service transmits data via UDP to a remote node. The transmission of the
                    data is immediately performed with this function call by forwarding it to EthIf.
 * @param[in]       SocketId: Socket identifier of the related local socket resource.
 * @param[in]       DataPtr: Pointer to a linear buffer of TotalLength bytes containing the data to
                    be transmitted. In case DataPtr is a NULL_PTR, TcpIp shall retrieve data from
                    upper layer via callback <Up>_CopyTxData().
 * @param[in]       RemoteAddrPtr: IP address and port of the remote host to transmit to.
 * @param[in]       TotalLength: indicates the payload size of the UDP datagram.
 * @return          Std_ReturnType
 * @retval          E_OK: Request to transmit the UDP message has been accepted.
 * @retval          E_NOT_OK: UDP message could not be sent because of a permanent error, e.g.
                    message is too long.
 * @synchronous     TRUE
 * @reentrant       Reentrant for different SocketIds. Non reentrant for the same SocketId.
 * @trace           CPD-69674
 */
extern Std_ReturnType TcpIp_UdpTransmit(
    TcpIp_SocketIdType        SocketId,
    const uint8*              DataPtr,
    const TcpIp_SockAddrType* RemoteAddrPtr,
    uint16                    TotalLength);
#endif

#if (STD_ON == TCPIP_TCP_ENABLED)
/**
 * @brief           This service requests transmission of data via TCP to a remote node. The
                    transmission of the data is decoupled.
 * @param[in]       SocketId: Socket identifier of the related local socket resource.
 * @param[in]       DataPtr: Pointer to a linear buffer of AvailableLength bytes containing
                    the data to be transmitted. In case DataPtr is a NULL_PTR, TcpIp shall
                    retrieve data from upper layer via callback <Up>_CopyTx Data().
 * @param[in]       AvailableLength: Available data for transmission in bytes.
 * @param[in]       ForceRetrieve: This parameter is only valid if DataPtr is a NULL_PTR. Indicates
                    how the TCP/IP stack retrieves data from upper layer if DataPtr is a NULL_PTR.
                    TRUE: the whole data indicated by availableLength shall be retrieved from the
                    upper layer via one or multiple <Up>_ CopyTxData() calls within the context of
                    this transmit function.
                    FALSE: The TCP/IP stack may retrieve up to availableLength data from the upper
                    layer. It is allowed to retrieve less than availableLength bytes.
 * @return          Std_ReturnType
 * @retval          E_OK: The request has been accepted.
 * @retval          E_NOT_OK: The request has not been accepted, e.g. due to a lack of buffer space
                    or the socket is not connected.
 * @synchronous     FALSE
 * @reentrant       Reentrant for different SocketIds. Non reentrant for the same SocketId.
 * @trace           CPD-69675
 */
extern Std_ReturnType
    TcpIp_TcpTransmit(TcpIp_SocketIdType SocketId, const uint8* DataPtr, uint32 AvailableLength, boolean ForceRetrieve);
#endif

/**
 * @brief           By this API service the TCP/IP stack gets an indication and the data of
                    a received frame.
 * @param[in]       CtrlIdx: Index of the EthIf controller.
 * @param[in]       FrameType: frame type of received Ethernet frame.
 * @param[in]       IsBroadcast: parameter to indicate a broadcast frame.
 * @param[in]       PhysAddrPtr: pointer to Physical source address (MAC address in network
                    byte order) of received Ethernet frame.
 * @param[in]       DataPtr: Pointer to payload of the received Ethernet frame (i.e. Ethernet
                    header is not provided).
 * @param[in]       LenByte: Length of received data.
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69676
 */
extern void TcpIp_RxIndication(
    uint8         CtrlIdx,
    Eth_FrameType FrameType,
    boolean       IsBroadcast,
    const uint8*  PhysAddrPtr,
    const uint8*  DataPtr,
    uint16        LenByte);

#if (STD_ON == TCPIP_PARTITION_USED)
/**
 * @brief           Schedules the TCP/IP stack. (Entry point for scheduling)
 * @param[in]       partitionIndex: Index of partition.
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69677
 */
extern void TcpIp_MainFunction(ApplicationType partitionIndex);
#else
/**
 * @brief           Schedules the TCP/IP stack. (Entry point for scheduling)
 * @synchronous     TRUE
 * @reentrant       Non reentrant
 * @trace           CPD-69677
 */
extern void TcpIp_MainFunction(void);
#endif

#ifdef __cplusplus
}
#endif

#endif
